package com.design_patterns.proxy.v1;

import java.util.Random;

/**
 * @author: 李德才
 * @description:
 * @create: 2020-08-30 17:33
 **/

/**
 * 代理模式，代理对象级别较低，无法完成组合
 */
public class Main {
    public static void main(String[] args) {
//        System.err.println(" before Drawing ");
//        new Brush().drawing();
//        System.err.println(" after Drawing ");
        new BrushLog(new Brush()).drawing();
    }


}

class Brush implements Drawing {

    @Override
    public void drawing() {
        System.err.println("画笔开始画画");
        try {
            Thread.sleep(new Random().nextInt(5000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("画笔绘画完成");
    }
}

class BrushLog implements Drawing {
    Brush brush;

    public BrushLog(Brush brush) {
        this.brush = brush;
    }


    private void before() {
        System.err.println(" before Drawing ");
    }

    private void after() {
        System.err.println(" after Drawing ");
    }

    @Override
    public void drawing() {
        before();
        brush.drawing();
        after();
    }
}


interface Drawing {
    void drawing();
}